package com.chen.controller.admin;

import com.chen.common.result.Result;
import com.chen.popj.dto.ContestDTO;
import com.chen.popj.entity.Contest;
import com.chen.service.ContestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@Slf4j
@RestController(value = "adminContestController")
@RequestMapping("/admin")
public class ContestController {

    @Autowired
    ContestService contestService;

    /**
     * 创建比赛
     *
     * @param contestDTO
     * @return
     */
    @PostMapping("/contest")
    public Result<Object> createContest(@RequestBody ContestDTO contestDTO) {
        System.out.println(contestDTO);
        Integer id = contestService.createContest(contestDTO);
        String contestUrl = "http://localhost:8123/contest/acm/" + id;
        String contestRegistrationUrl = "http://localhost:8123/contest/acm/Registration/" + id;
        log.info("比赛URL:" + contestUrl);
        log.info("报名URL:" + contestRegistrationUrl);
        ArrayList<String> urlList = new ArrayList<>();
        urlList.add(contestUrl);
        urlList.add(contestRegistrationUrl);
        return Result.success(urlList);
    }
}
